﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using System.Web.Security;

namespace HMS.Security
{
    public class HMSIdentity : IIdentity
    {
        # region private variables
		
		private String userId;
		public int userPK;
		private bool login;
		private bool isSuperUser;
		private string fullName;
		private string userEmail;
		private string roles;
        private bool IsDashboardAllowed;
        private bool IsDimesionAllowed;
        private bool IsGroupingAllowed;
        private bool IsReportAllowed;
        private bool IsConfigAllowed;

		#endregion

		# region constructors
		/// <summary>
		/// The default constructor initializes any fields to their default values.
		/// </summary>
		public HMSIdentity()
		{
			this.userPK			= 0;
			this.userId			= String.Empty;
			this.login			= false;
			this.isSuperUser	= false;
			this.fullName		= String.Empty;
			this.userEmail		= String.Empty;
			this.roles			= String.Empty;
            this.IsDashboardAllowed = false;
            this.IsDimesionAllowed = false;
            this.IsGroupingAllowed = false;
            this.IsReportAllowed = false;
            this.IsConfigAllowed = false;
		}

		/// <summary>
		/// Initializes a new instance of the CustomIdentity class 
		/// with the passed parameters
		/// </summary>
		/// <param name="uId">User ID of the user</param>
		/// <param name="upk">Primary Key of the User record in User table</param>
		/// <param name="islogin">Flag that indicates whether the user has been authenticated</param>
		/// <param name="isAdmin">Flag that indicates whether the user is an Administrator</param>
		/// <param name="userName">Full name of the User</param>
		/// <param name="email">Email of the User</param>
		public HMSIdentity(string uId, int upk, bool islogin, bool isAdmin, string userName, string email, string uRoles)
		{
			this.userPK			= upk;
			this.userId			= uId;
			this.login			= islogin;
			this.isSuperUser	= isAdmin;
			this.fullName		= userName;
			this.userEmail		= email;
			this.roles			= uRoles;
		}


        /// <summary>
        /// Initializes a new instance of the CustomIdentity class 
        /// with the passed parameters
        /// </summary>
        /// <param name="uId">User ID of the user</param>
        /// <param name="upk">Primary Key of the User record in User table</param>
        /// <param name="islogin">Flag that indicates whether the user has been authenticated</param>
        /// <param name="isAdmin">Flag that indicates whether the user is an Administrator</param>
        /// <param name="userName">Full name of the User</param>
        /// <param name="email">Email of the User</param>
        /// <param name="uRoles">user roles</param>
        /// <param name="IsDashboardAllowed">dashboard allowed/not</param>
        /// <param name="IsDimesionAllowed">dimension allowed/not</param>
        /// <param name="IsGroupingAllowed">grouping allowed/not</param>
        /// <param name="IsReportAllowed">report allowed/not</param>
        /// <param name="IsConfigAllowed">config allowed/not</param>
        public HMSIdentity(string uId, int upk, bool islogin, bool isAdmin, string userName, string email, string uRoles, bool IsDashboard, bool IsDimesion, bool IsGrouping, bool IsReport, bool IsConfig)
        {
            
            this.userPK = upk;
            this.userId = uId;
            this.login = islogin;
            this.isSuperUser = isAdmin;
            this.fullName = userName;
            this.userEmail = email;
            this.roles = uRoles;
            this.IsDashboardAllowed = IsDashboard;
            this.IsDimesionAllowed = IsDimesion;
            this.IsGroupingAllowed = IsGrouping;
            this.IsReportAllowed = IsReport;
            this.IsConfigAllowed= IsConfig;
        }

		#endregion

		# region properties
		// Properties
		/// <summary>
		/// Gets the Authentication Type
		/// </summary>
		public string AuthenticationType 
		{
			get { return "Custom"; }
		}

		/// <summary>
		/// Indicates whether the User is authenticated
		/// </summary>
		public bool IsAuthenticated  
		{
			get { return login; }
			set { login = value; }
		}

		/// <summary>
		/// Gets or sets the UserID of the User
		/// </summary>
		public string Name 
		{
			get { return userId; }
			set { userId = value; }
		}

		/// <summary>
		/// Gets or sets the Primary Key for the User record
		/// </summary>
		public int UserPK 
		{
			get { return userPK; }
			set { userPK = value; }
		}

		/// <summary>
		/// Indicates whether the User is an Administrator
		/// </summary>
		public bool IsSuperUser
		{
			get { return isSuperUser; }
			set { isSuperUser = value; }
		}

		/// <summary>
		/// Gets or sets the Full Name of the User
		/// </summary>
		public string UserFullName
		{
			get { return fullName; }
			set { fullName = value; }
		}

		/// <summary>
		/// Gets or sets the Email of the User
		/// </summary>
		public string UserEmail
		{
			get { return userEmail; }
			set { userEmail = value; }
		}

		/// <summary>
		/// Gets or sets the Roles of the User
		/// The roles are stored in a pipe "|" separated string
		/// </summary>
		public string UserRoles
		{
			get { return roles; }
			set { roles = value; }
		}

        /// <summary>
        /// Indicates whether the User is authorised for Dashboard tab
        /// </summary>
        public bool IsDashboard
        {
            get { return IsDashboardAllowed; }
            set { IsDashboardAllowed = value; }
        }
        /// <summary>
        /// Indicates whether the User is authorised for Dimesion tab
        /// </summary>
        public bool IsDimesion
        {
            get { return IsDimesionAllowed; }
            set { IsDimesionAllowed = value; }
        }
        /// <summary>
        /// Indicates whether the User is authorised for Grouping tab
        /// </summary>
        public bool IsGrouping
        {
            get { return IsGroupingAllowed; }
            set { IsGroupingAllowed = value; }
        }
        /// <summary>
        /// Indicates whether the User is authorised for Report tab
        /// </summary>
        public bool IsReport
        {
            get { return IsReportAllowed; }
            set { IsReportAllowed = value; }
        }
        /// <summary>
        /// Indicates whether the User is authorised for Config tab
        /// </summary>
        public bool IsConfig
        {
            get { return IsConfigAllowed; }
            set { IsConfigAllowed = value; }
        }

		#endregion
    }
}
